package com.lin.maker.generator;

import java.io.*;

public class JarGenerator {
    public static void doGenerator(String projectPath) throws IOException, InterruptedException {
        // 构建jar包命令
        String WindowMavencommand = "mvn.cmd clean package -Dmaven.test.skip=true";
        String LinuxMavencommand = "mvn clean package -Dmaven.test.skip=true";//Linux或者Mac
        //使用 ProcessBuilder 来运行一个 Maven 命令（通过 WindowMavencommand）并且在指定的项目路径 projectPath 中执行该命令。
        ProcessBuilder processBuilder = new ProcessBuilder(WindowMavencommand.split(" "));
        processBuilder.directory(new File(projectPath));
        Process process = processBuilder.start();
        InputStream inputStream = process.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }
        int exitCode = process.waitFor();
        System.out.println("命令执行退出码"+exitCode);
        bufferedReader.close();
    }
}
